package com.example.springboot_jap_model.task;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 1.定时任务 注解
 */
@Component
public class TestTask {
    private final static Logger logger = LoggerFactory.getLogger(TestTask.class);
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    /**
     * 6秒 执行一次
     */
    //@Scheduled(fixedRate = 600000)
    public void reportCurrentTime() {
//        System.out.println("现在时间：" + dateFormat.format(new Date()));
        logger.info("当前时间reportCurrentTime:{}",dateFormat.format(new Date()));
    }

    /**
     * 每隔五分钟执行一次
     */
    //@Scheduled(cron = "0 0/1 * * * ?")
    public void reportCurrentTimeForCron() {
//        System.out.println("现在时间reportCurrentTimeForCron：" + dateFormat.format(new Date()));
        logger.info("当前时间:{}",dateFormat.format(new Date()));
    }

}
